package main

import (
	"fmt"
	"os"
	"encoding/json"
	"github.com/robfig/cron"
	"log"
)

/**
	定时任务
 */

type configuration struct {
	Run    string
}



func main() {
	i := 0
	c := cron.New()
	file, _ := os.Open("src/go-monitor/job/job.json")
	defer file.Close()
	decoder := json.NewDecoder(file)
	conf := configuration{}
	err := decoder.Decode(&conf)
	if err != nil {
		fmt.Println("Error:", err)
	}
	//fmt.Println(conf.Run)
	spec := conf.Run

	c.AddFunc(spec, func() {
		i++
		log.Println("cron running : ", i)
	})

	c.AddJob(spec, TestJob{})
	c.AddJob(spec, Test2Job{})

	c.Start()
	defer c.Stop()
	select {}
}

type TestJob struct {
}

type Test2Job struct {
}

func (this TestJob) Run() {
	fmt.Println("testJob1...")
}

func (this Test2Job) Run() {
	fmt.Println("testJob2...")

}
